package game.module.dabt.logic;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import game.common.AwardConstants;
import game.common.ItemConstants;
import game.entity.PlayingRole;
import game.module.award.logic.AwardUtil;
import game.module.award.logic.ModuleConstants;
import game.module.item.logic.ItemManager;
import game.module.user.bean.PlayerBean;
import game.module.user.dao.PlayerDao;
import game.session.SessionManager;

public class ChargeRoomFee {
	private static Logger logger = LoggerFactory.getLogger(ChargeRoomFee.class);

	static class SingletonHolder {
		static ChargeRoomFee instance = new ChargeRoomFee();
	}

	public static ChargeRoomFee getInstance() {
		return SingletonHolder.instance;
	}

	/**
	 * 房主出钱：1 ,player里存了所有的玩家 AA 2,player里存了所有的玩家 赢家出钱,player里面存了一个大赢家
	 */
	public void tollfee(short fee, byte chargeType, List<Integer> player) {
		if (chargeType == 0) {// 房主收费
			logger.info("roomfee toll fangzhu pay");
			PlayingRole pr = SessionManager.getInstance().getPlayer(player.get(0));
			ItemManager.getInstance().reduceItemsAndPush(pr.getId(), ItemConstants.FANG_KA_ITEM_ID,
					fee);
		}
		if (chargeType == 1) {// AA
			logger.info("roomfee toll fangzhu AA");
			short averageFee = (short) (fee / player.size());
			for (Integer aPlayer : player) {
				PlayingRole pr = SessionManager.getInstance().getPlayer(aPlayer);
				ItemManager.getInstance().reduceItemsAndPush(pr.getId(), ItemConstants.FANG_KA_ITEM_ID,
						averageFee);

			}
		}
		if (chargeType == 2) {// 赢家结算
			logger.info("roomfee toll winner AA");
			short averageFee = (short) (fee / player.size());
			for (Integer aPlayer : player) {
				PlayingRole pr = SessionManager.getInstance().getPlayer(aPlayer);
				ItemManager.getInstance().reduceItemsAndPush(pr.getId(), ItemConstants.FANG_KA_ITEM_ID,
						averageFee);
			}
		}
	}
}
